package com.chy.blog_server.modular.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chy.blog_server.modular.system.entity.SysMenu;
import com.chy.blog_server.modular.system.entity.vo.SysMenuTreeVO;
import com.chy.blog_server.modular.system.entity.vo.SysMenuTreeVOTwo;
import com.chy.blog_server.modular.system.mapper.SysMenuMapper;
import com.chy.blog_server.modular.system.service.ISysMenuService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 描述：菜单表 service业务层
 * 作者：chenhuiyan
 * 时间：2019/9/28 12:03
 */
@Service
@Transactional(readOnly = true)
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService {

    /**
     * 查询菜单树列表
     * @return
     */
    @Override
    @Cacheable(value = "sysMenuTreeVO")
    public SysMenuTreeVO getMenuTreeList(){
        return baseMapper.getMenuTreeList();
    }

    /**
     * 获取菜单列表(菜单管理)
     * @return
     */
    @Override
    public List<Map<String, Object>> getMenuListToManager(){
        return baseMapper.getMenuListToManager();
    }

    /**
     * 查询菜单树列表（添加菜单树列表）
     * @return
     */
    @Override
    public SysMenuTreeVOTwo getMenuTreeListTwo(){
        return baseMapper.getMenuTreeListTwo();
    }

    /**
     * 保存
     * @param sysMenu
     * @param request
     */
    public void saveData(SysMenu sysMenu, HttpServletRequest request){
        sysMenu.preInsert(request);
        baseMapper.insert(sysMenu);
    }

    /**
     * 根据id查找信息
     * @param id
     * @return
     */
    public Map<String, Object> getInfoById(String id){
        return baseMapper.getInfoById(id);
    }

}
